package com.kc.road.camera.service;


import com.kc.road.camera.common.Constants;
import com.kc.road.camera.util.ContinueFTP;
import com.kc.road.camera.util.JacksonUtil;
import com.kc.road.camera.util.UuidUtils;
import com.kc.road.camera.vo.CameraVo;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 摄像头处理类
 *
 * @author lenovo
 */
@Service
public class CameraService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;

    //private static NativeLong lUserID;//用户句柄1

    /**
     * 摄像头ip，如果摄像头ip变换，则必须修改以下ip地址，多个ip用","隔开
     */
    private static String devIps = "192.168.70.180,192.168.70.181";
    /**
     * 将设备放入
     */
    private static List<NativeLong> lUserIDList;

    // private static NativeLong lAlarmHandle;//报警布防句柄1
    /**
     * 将报警布防句柄放入
     */
    private static List<NativeLong> lAlarmHandleList;

    private static FMSGCallBack fMSFCallBack;//报警回调函数实现

    public void doIt() {

        String initResult = this.initSdk();
        if (null != initResult) {
            //初始化SDk成功
            logger.info(initResult);
            //注册
            this.register();
            //布防
            this.SetupAlarmChan();
            //撤防
            // this.CloseAlarmChan();
            //注销
            // this.Logout();
            //  this.oneTest();

        } else {
            logger.info("sdk初始化失败");
        }
    }

    private void oneTest() {
        //触发参数
        HCNetSDK.NET_DVR_SNAPCFG struSnapCfg = new HCNetSDK.NET_DVR_SNAPCFG();
        struSnapCfg.dwSize = struSnapCfg.size();//结构体大小
        struSnapCfg.bySnapTimes = 2;//连拍
        struSnapCfg.wSnapWaitTime = 100;//抓拍等待时间
        struSnapCfg.write();

        if (null != lUserIDList && lUserIDList.size() > 0) {
            String[] devIpList = devIps.split(",");
            for (int i = 0; i < lUserIDList.size(); i++) {
                //网络触发抓拍
                if (false == hCNetSDK.NET_DVR_ContinuousShoot(lUserIDList.get(i), struSnapCfg)) {
                    int iErr = hCNetSDK.NET_DVR_GetLastError();
                    logger.info(i + "号设备网络触发失败，错误号：" + iErr + "===" + devIpList[i]);
                    break;
                }

                HCNetSDK.NET_DVR_CHANNEL_GROUP mstruChanGroup = new HCNetSDK.NET_DVR_CHANNEL_GROUP();
                mstruChanGroup.dwSize = mstruChanGroup.size();
                mstruChanGroup.dwChannel = 1;
                HCNetSDK.NET_VCA_TRAVERSE_PLANE_DETECTION mstruTraverseCfg = new HCNetSDK.NET_VCA_TRAVERSE_PLANE_DETECTION();
                IntByReference pInt = new IntByReference(0);
                Pointer lpStatusList = pInt.getPointer();
                mstruChanGroup.write();
                mstruTraverseCfg.write();

                Pointer lpCond = mstruChanGroup.getPointer();
                Pointer lpInbuferCfg = mstruTraverseCfg.getPointer();
                //参数配置
                if (false == hCNetSDK.NET_DVR_GetDeviceConfig(lUserIDList.get(i), HCNetSDK.NET_DVR_GET_TRAVERSE_PLANE_DETECTION, 1, lpCond, mstruChanGroup.size(),
                        lpStatusList, lpInbuferCfg, mstruTraverseCfg.size())) {
                    int iErr = hCNetSDK.NET_DVR_GetLastError();
                    logger.info("参数配置===========================" + iErr + "===" + devIpList[i]);
                    break;
                }
                mstruTraverseCfg.read();
            }
        }
    }

    /**
     * 初始化SDk
     *
     * @return String
     */
    private String initSdk() {
        lUserIDList = new ArrayList<>();
        lAlarmHandleList = new ArrayList<>();
        fMSFCallBack = null;
        boolean initSuc = hCNetSDK.NET_DVR_Init();
        if (!initSuc) {
            return null;
        }
        hCNetSDK.NET_DVR_SetConnectTime(2000, 1);
        hCNetSDK.NET_DVR_SetReconnect(10000, true);
        return "";
    }


    HCNetSDK.NET_DVR_DEVICEINFO_V30 strDeviceInfo;//设备信息

    /**
     * 注册设备信息
     */
    private void register() {
        //注册之前先注销已注册的用户,预览情况下不可注销 后面控制台控制新设备的添加
        strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
        //设备ip地址
        String[] devIpList = devIps.split(",");
        if (devIpList.length > 0) {
            for (int i = 0; i < devIpList.length; i++) {
                NativeLong temp = hCNetSDK.NET_DVR_Login_V30(devIpList[i],
                        (short) 8000, "admin", "kc123456", strDeviceInfo);
                lUserIDList.add(temp);
                long userID = temp.longValue();
                logger.info(i + "号设备注册成功====" + devIpList[i]);
                if (userID == -1) {
                    logger.info(i + "号设备注册失败====" + devIpList[i]);
                }
            }
        }
    }

    /**
     * 布防
     */
    private void SetupAlarmChan() {
        if (null != lUserIDList && lUserIDList.size() > 0) {
            if (fMSFCallBack == null) {
                fMSFCallBack = new FMSGCallBack();
                Pointer pUser = null;
                if (!hCNetSDK.NET_DVR_SetDVRMessageCallBack_V30(fMSFCallBack, pUser)) {
                    logger.info("设置回调函数失败!");
                }
            }
            for (int i = 0; i < lUserIDList.size(); i++) {
                HCNetSDK.NET_DVR_SETUPALARM_PARAM strAlarmInfo = new HCNetSDK.NET_DVR_SETUPALARM_PARAM();
                strAlarmInfo.dwSize = strAlarmInfo.size();
                strAlarmInfo.byLevel = 1;//等级
                strAlarmInfo.byAlarmInfoType = 1;
                strAlarmInfo.write();
                NativeLong temp = hCNetSDK.NET_DVR_SetupAlarmChan_V41(lUserIDList.get(i), strAlarmInfo);
                lAlarmHandleList.add(temp);
                if (temp.intValue() == -1) {
                    logger.info(i + "号设备布防失败");
                } else {
                    logger.info(i + "号设备布防成功");
                }
            }
        }
    }

    /**
     * 报警撤防
     */
    public void CloseAlarmChan() {
        //报警撤防
//        if (lAlarmHandle.intValue() > -1) {
//            if (hCNetSDK.NET_DVR_CloseAlarmChan_V30(lAlarmHandle)) {
//                logger.info("撤防成功");
//
//                lAlarmHandle = new NativeLong(-1);
//            }
//        }
    }

    /**
     * 注销
     */
    public void Logout() {
        //报警撤防
//        if (lAlarmHandle.intValue() > -1) {
//            if (!hCNetSDK.NET_DVR_CloseAlarmChan_V30(lAlarmHandle)) {
//                logger.info("撤防失败");
//
//            } else {
//                lAlarmHandle = new NativeLong(-1);
//            }
//        }
//
//        //注销
//        if (lUserID.longValue() > -1) {
//            if (hCNetSDK.NET_DVR_Logout(lUserID)) {
//                logger.info("注销成功");
//                lUserID = new NativeLong(-1);
//            }
//        }
    }

    @Autowired
    private RabbitMessageSenderService rabbitMessageSenderService;

    /**
     * 报警信息回调函数
     */
    @Service
    public class FMSGCallBack implements HCNetSDK.FMSGCallBack {

        //@Autowired
        //private RabbitMessageSenderService senderService;

        /**
         * mq消息发送
         *
         * @param key 路由key
         * @param vo  消息体
         */
        private void messageSender(String key, CameraVo vo) {
            logger.info("key=" + key);
            //logger.info("senderService="+senderService);
            //logger.info("rabbitMessageSenderService="+rabbitMessageSenderService);
            //logger.info("CameraService.this.rabbitMessageSenderService=" + CameraService.this.rabbitMessageSenderService);
            logger.info("vo=" + JacksonUtil.toJSon(vo));
            //String routingKey = Constants.WIFI_ROUTING_TOPIC_KEY + "." + key;
            String routingKey = Constants.CAMERA_ROUTING_TOPIC_KEY + "." + key;
            //senderService.sender(Constants.CAMERA_EXCHANGE, routingKey, vo);
            /*rabbitMessageSenderService.sender(Constants.CAMERA_EXCHANGE, routingKey, vo);*/
            rabbitMessageSenderService.sender(Constants.CAMERA_EXCHANGE, routingKey, vo);
        }

        @Override
        public void invoke(NativeLong lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
            String sAlarmType;
            String[] sIP = new String[2];
            sAlarmType = "lCommand=" + lCommand.intValue();

            //lCommand是传的报警类型
            switch (lCommand.intValue()) {
                case HCNetSDK.COMM_ALARM_V30:
                    HCNetSDK.NET_DVR_ALARMINFO_V30 strAlarmInfoV30 = new HCNetSDK.NET_DVR_ALARMINFO_V30();
                    strAlarmInfoV30.write();
                    Pointer pInfoV30 = strAlarmInfoV30.getPointer();
                    pInfoV30.write(0, pAlarmInfo.getByteArray(0, strAlarmInfoV30.size()), 0, strAlarmInfoV30.size());
                    strAlarmInfoV30.read();
                    switch (strAlarmInfoV30.dwAlarmType) {
                        case 0:
                            sAlarmType = sAlarmType + new String("：信号量报警") + "，" + "报警输入口：" + (strAlarmInfoV30.dwAlarmInputNumber + 1);
                            break;
                        case 1:
                            sAlarmType = sAlarmType + new String("：硬盘满");
                            break;
                        case 2:
                            sAlarmType = sAlarmType + new String("：信号丢失");
                            break;
                        case 3:
                            sAlarmType = sAlarmType + new String("：移动侦测") + "，" + "报警通道：";
                            for (int i = 0; i < 64; i++) {
                                if (strAlarmInfoV30.byChannel[i] == 1) {
                                    sAlarmType = sAlarmType + "ch" + (i + 1) + " ";
                                }
                            }
                            break;
                        case 4:
                            sAlarmType = sAlarmType + new String("：硬盘未格式化");
                            break;
                        case 5:
                            sAlarmType = sAlarmType + new String("：读写硬盘出错");
                            break;
                        case 6:
                            sAlarmType = sAlarmType + new String("：遮挡报警");
                            break;
                        case 7:
                            sAlarmType = sAlarmType + new String("：制式不匹配");
                            break;
                        case 8:
                            sAlarmType = sAlarmType + new String("：非法访问");
                            break;
                    }
                    //报警设备IP地址 sIP[0]
                    //sIP = new String(pAlarmer.sDeviceIP).split("\0", 2);
                    break;
                case HCNetSDK.COMM_ALARM_RULE:
                    HCNetSDK.NET_VCA_RULE_ALARM strVcaAlarm = new HCNetSDK.NET_VCA_RULE_ALARM();
                    strVcaAlarm.write();
                    Pointer pVcaInfo = strVcaAlarm.getPointer();
                    pVcaInfo.write(0, pAlarmInfo.getByteArray(0, strVcaAlarm.size()), 0, strVcaAlarm.size());
                    strVcaAlarm.read();

                    switch (strVcaAlarm.struRuleInfo.wEventTypeEx) {
                        case 1:
                            sAlarmType = sAlarmType + new String("：穿越警戒面") + "，" +
                                    "_wPort:" + strVcaAlarm.struDevInfo.wPort +
                                    "_byChannel:" + strVcaAlarm.struDevInfo.byChannel +
                                    "_byIvmsChannel:" + strVcaAlarm.struDevInfo.byIvmsChannel +
                                    "_Dev IP：" + new String(strVcaAlarm.struDevInfo.struDevIP.sIpV4);
                            break;
                        case 2:
                            sAlarmType = sAlarmType + new String("：目标进入区域") + "，" +
                                    "_wPort:" + strVcaAlarm.struDevInfo.wPort +
                                    "_byChannel:" + strVcaAlarm.struDevInfo.byChannel +
                                    "_byIvmsChannel:" + strVcaAlarm.struDevInfo.byIvmsChannel +
                                    "_Dev IP：" + new String(strVcaAlarm.struDevInfo.struDevIP.sIpV4);
                            break;
                        case 3:
                            sAlarmType = sAlarmType + new String("：目标离开区域") + "，" +
                                    "_wPort:" + strVcaAlarm.struDevInfo.wPort +
                                    "_byChannel:" + strVcaAlarm.struDevInfo.byChannel +
                                    "_byIvmsChannel:" + strVcaAlarm.struDevInfo.byIvmsChannel +
                                    "_Dev IP：" + new String(strVcaAlarm.struDevInfo.struDevIP.sIpV4);
                            break;
                        default:
                            sAlarmType = sAlarmType + new String("：其他行为分析报警") + "，" +
                                    "_wPort:" + strVcaAlarm.struDevInfo.wPort +
                                    "_byChannel:" + strVcaAlarm.struDevInfo.byChannel +
                                    "_byIvmsChannel:" + strVcaAlarm.struDevInfo.byIvmsChannel +
                                    "_Dev IP：" + new String(strVcaAlarm.struDevInfo.struDevIP.sIpV4);
                            break;
                    }
                    //报警设备IP地址
//                    sIP = new String(pAlarmer.sDeviceIP).split("\0", 2);
                    if (strVcaAlarm.dwPicDataLen > 0) {
                        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
                        String newName = sf.format(new Date());
                        FileOutputStream fout;
                        try {
                            fout = new FileOutputStream("/home/lenovo/road" + newName + "01.jpg");
                            //将字节写入文件
                            long offset = 0;
                            ByteBuffer buffers = strVcaAlarm.pImage.getPointer().getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
                            byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
                            buffers.rewind();
                            buffers.get(bytes);
                            fout.write(bytes);
                            fout.close();
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                    break;
                case HCNetSDK.COMM_UPLOAD_PLATE_RESULT:
                    HCNetSDK.NET_DVR_PLATE_RESULT strPlateResult = new HCNetSDK.NET_DVR_PLATE_RESULT();
                    strPlateResult.write();
                    Pointer pPlateInfo = strPlateResult.getPointer();
                    pPlateInfo.write(0, pAlarmInfo.getByteArray(0, strPlateResult.size()), 0, strPlateResult.size());
                    strPlateResult.read();
//                    try {
//                        String srt3 = new String(strPlateResult.struPlateInfo.sLicense, "GBK");
//                        sAlarmType = sAlarmType + "：交通抓拍上传，车牌：" + srt3;
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
                    //报警设备IP地址
//                    sIP = new String(pAlarmer.sDeviceIP).split("\0", 2);
                    if (strPlateResult.dwPicLen > 0) {
                        String local = UuidUtils.getDateUuid();
                        String localName = "/home/lenovo/img/" + local.substring(local.lastIndexOf("/") + 1, local.length()) + ".jpg";
                        String remoteName = "home/" + local + ".jpg";
                        FileOutputStream fout;
                        try {
                            fout = new FileOutputStream(localName);
                            //将字节写入文件
                            long offset = 0;
                            ByteBuffer buffers = strPlateResult.pBuffer1.getByteBuffer(offset, strPlateResult.dwPicLen);
                            byte[] bytes = new byte[strPlateResult.dwPicLen];
                            buffers.rewind();
                            buffers.get(bytes);
                            fout.write(bytes);
                            fout.close();
                            // 调用ftp服务，上传图片
                            ContinueFTP.UploadStatus status = ContinueFTP.uploadImage(localName, remoteName);
                            // 删除本地图片
                            File file = new File(localName);
                            file.delete();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    break;
                case HCNetSDK.COMM_ITS_PLATE_RESULT:
                    CameraVo vo = new CameraVo();
                    HCNetSDK.NET_ITS_PLATE_RESULT strItsPlateResult = new HCNetSDK.NET_ITS_PLATE_RESULT();
                    strItsPlateResult.write();
                    Pointer pItsPlateInfo = strItsPlateResult.getPointer();
                    pItsPlateInfo.write(0, pAlarmInfo.getByteArray(0, strItsPlateResult.size()), 0, strItsPlateResult.size());
                    strItsPlateResult.read();
                    //采集时间
                    StringBuilder sb = new StringBuilder("");
                    sb.append(strItsPlateResult.struSnapFirstPicTime.wYear).append("-")
                            .append(strItsPlateResult.struSnapFirstPicTime.byMonth).append("-")
                            .append(strItsPlateResult.struSnapFirstPicTime.byDay).append(" ")
                            .append(strItsPlateResult.struSnapFirstPicTime.byHour).append(":")
                            .append(strItsPlateResult.struSnapFirstPicTime.byMinute).append(":")
                            .append(strItsPlateResult.struSnapFirstPicTime.bySecond).append(":")
                            .append(strItsPlateResult.struSnapFirstPicTime.wMilliSec);
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
                    try {
                        Date recordDate = sdf.parse(sb.toString());
                        vo.setAbsTime(recordDate);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    try {
                        // 车牌号码
                        String srt3 = new String(strItsPlateResult.struPlateInfo.sLicense, "GBK");
                        if (srt3.trim().contains("无车牌")) {
                            vo.setLicense(srt3.trim());
                        } else {
                            vo.setLicense(srt3.trim().substring(1, srt3.trim().length()));
                            vo.setLicenseColor(srt3.trim().substring(0, 1));
                        }
                        sAlarmType = sAlarmType + ",车辆类型：" + strItsPlateResult.byVehicleType + ",交通抓拍上传，车牌：" + srt3;
                        // 车辆类型
                        vo.setVehicleType(strItsPlateResult.byVehicleType);
                        logger.info(sAlarmType + "jiegou");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    //报警设备IP地址
                    logger.info("IP解析前地址==" + new String(pAlarmer.sDeviceIP));
                    sIP = new String(pAlarmer.sDeviceIP).split("\0", 2);
                    logger.info("IP解析后地址==" + JacksonUtil.toJSon(sIP));
                    vo.setIp(sIP[0]);
                    vo.setSpeed(strItsPlateResult.wSpeedLimit);
                    List<String> imgUrlList = new ArrayList<>();
                    for (int i = 0; i < strItsPlateResult.dwPicNum; i++) {
                        if (strItsPlateResult.struPicInfo[i].dwDataLen > 0) {
                            String local = UuidUtils.getDateUuid();
                            String localName = "/home/lenovo/img/" + local.substring(local.lastIndexOf("/") + 1, local.length()) + ".jpg";
                            String remoteName = "home/" + local + ".jpg";
                            FileOutputStream fout;
                            try {
                                fout = new FileOutputStream(localName);
                                //将字节写入文件
                                long offset = 0;
                                ByteBuffer buffers = strItsPlateResult.struPicInfo[i].pBuffer.getByteBuffer(offset, strItsPlateResult.struPicInfo[i].dwDataLen);
                                byte[] bytes = new byte[strItsPlateResult.struPicInfo[i].dwDataLen];
                                buffers.rewind();
                                buffers.get(bytes);
                                fout.write(bytes);
                                fout.close();
                                // 调用ftp服务，上传图片
                                ContinueFTP.UploadStatus status = ContinueFTP.uploadImage(localName, remoteName);
                                logger.info("图片上传远程路径=" + remoteName);
                                logger.info("图片上传结果=" + status.name());
                                // 删除本地图片
                                File file = new File(localName);
                                file.delete();
                                imgUrlList.add(remoteName);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    if (imgUrlList.size() > 0) {
                        vo.setImgUrl(imgUrlList);
                    }
                    vo.setCreateDate(new Date());
                    //发送rabbitmq消息
                    this.messageSender(sIP[0], vo);
                    break;
                case HCNetSDK.COMM_ALARM_PDC:
                    HCNetSDK.NET_DVR_PDC_ALRAM_INFO strPDCResult = new HCNetSDK.NET_DVR_PDC_ALRAM_INFO();
                    strPDCResult.write();
                    Pointer pPDCInfo = strPDCResult.getPointer();
                    pPDCInfo.write(0, pAlarmInfo.getByteArray(0, strPDCResult.size()), 0, strPDCResult.size());
                    strPDCResult.read();
//                    sAlarmType = sAlarmType + "：客流量统计，进入人数：" + strPDCResult.dwEnterNum + "，离开人数：" + strPDCResult.dwLeaveNum;
                    //报警设备IP地址
//                    sIP = new String(strPDCResult.struDevInfo.struDevIP.sIpV4).split("\0", 2);
                    break;

                case HCNetSDK.COMM_ITS_PARK_VEHICLE:
                    HCNetSDK.NET_ITS_PARK_VEHICLE strItsParkVehicle = new HCNetSDK.NET_ITS_PARK_VEHICLE();
                    strItsParkVehicle.write();
                    Pointer pItsParkVehicle = strItsParkVehicle.getPointer();
                    pItsParkVehicle.write(0, pAlarmInfo.getByteArray(0, strItsParkVehicle.size()), 0, strItsParkVehicle.size());
                    strItsParkVehicle.read();
//                    try {
//                        String srtParkingNo = new String(strItsParkVehicle.byParkingNo).trim(); //车位编号
//                        String srtPlate = new String(strItsParkVehicle.struPlateInfo.sLicense, "GBK").trim(); //车牌号码
//                        sAlarmType = sAlarmType + ",停产场数据,车位编号：" + srtParkingNo + ",车位状态："
//                                + strItsParkVehicle.byLocationStatus + ",车牌：" + srtPlate;
//                    } catch (UnsupportedEncodingException e1) {
//                        e1.printStackTrace();
//                    }
                    //报警设备IP地址
//                    sIP = new String(pAlarmer.sDeviceIP).split("\0", 2);
                    for (int i = 0; i < strItsParkVehicle.dwPicNum; i++) {
                        if (strItsParkVehicle.struPicInfo[i].dwDataLen > 0) {
                            String local = UuidUtils.getDateUuid();
                            String localName = "/home/lenovo/img/" + local.substring(local.lastIndexOf("/") + 1, local.length()) + ".jpg";
                            String remoteName = "home/" + local + ".jpg";
                            FileOutputStream fout;
                            try {
                                fout = new FileOutputStream(localName);
                                //将字节写入文件
                                long offset = 0;
                                ByteBuffer buffers = strItsParkVehicle.struPicInfo[i].pBuffer.getByteBuffer(offset, strItsParkVehicle.struPicInfo[i].dwDataLen);
                                byte[] bytes = new byte[strItsParkVehicle.struPicInfo[i].dwDataLen];
                                buffers.rewind();
                                buffers.get(bytes);
                                fout.write(bytes);
                                fout.close();
                                // 调用ftp服务，上传图片
                                ContinueFTP.UploadStatus status = ContinueFTP.uploadImage(localName, remoteName);
                                // 删除本地图片
                                File file = new File(localName);
                                file.delete();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    break;
                case HCNetSDK.COMM_ALARM_TFS:
                    HCNetSDK.NET_DVR_TFS_ALARM strTFSAlarmInfo = new HCNetSDK.NET_DVR_TFS_ALARM();
                    strTFSAlarmInfo.write();
                    Pointer pTFSInfo = strTFSAlarmInfo.getPointer();
                    pTFSInfo.write(0, pAlarmInfo.getByteArray(0, strTFSAlarmInfo.size()), 0, strTFSAlarmInfo.size());
                    strTFSAlarmInfo.read();

//                    try {
//                        //车牌号码
//                        String srtPlate = new String(strTFSAlarmInfo.struPlateInfo.sLicense, Constants.CHARSET_GBK).trim();
//                        sAlarmType = sAlarmType + "：交通取值报警信息，违章类型：" + strTFSAlarmInfo.dwIllegalType + "，车牌号码：" + srtPlate;
//                    } catch (UnsupportedEncodingException e1) {
//                        e1.printStackTrace();
//                    }
                    //报警设备IP地址
//                    sIP = new String(strTFSAlarmInfo.struDevInfo.struDevIP.sIpV4).split("\0", 2);
                    break;
                    /*
                    实时人脸抓拍上传
                     */
                case HCNetSDK.COMM_UPLOAD_FACESNAP_RESULT:
                    HCNetSDK.NET_VCA_FACESNAP_RESULT strFaceSnapInfo = new HCNetSDK.NET_VCA_FACESNAP_RESULT();
                    strFaceSnapInfo.write();
                    Pointer pFaceSnapInfo = strFaceSnapInfo.getPointer();
                    pFaceSnapInfo.write(0, pAlarmInfo.getByteArray(0, strFaceSnapInfo.size()), 0, strFaceSnapInfo.size());
                    strFaceSnapInfo.read();

//                    sAlarmType = sAlarmType + "：人脸抓拍上传，人脸评分：" + strFaceSnapInfo.dwFaceScore + "，年龄段：" +
//                            strFaceSnapInfo.struFeature.byAgeGroup + "，性别：" + strFaceSnapInfo.struFeature.bySex;
                    //报警设备IP地址
                    //sIP = new String(strFaceSnapInfo.struDevInfo.struDevIP.sIpV4).split("\0", 2);
                    break;
                /*
                  人脸黑名单比对报警
                 */
                case HCNetSDK.COMM_SNAP_MATCH_ALARM:
                    HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM strFaceSnapMatch = new HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM();
                    strFaceSnapMatch.write();
                    Pointer pFaceSnapMatch = strFaceSnapMatch.getPointer();
                    pFaceSnapMatch.write(0, pAlarmInfo.getByteArray(0, strFaceSnapMatch.size()), 0, strFaceSnapMatch.size());
                    strFaceSnapMatch.read();

//                    sAlarmType = sAlarmType + "：人脸黑名单比对报警，相识度：" + strFaceSnapMatch.fSimilarity + "，黑名单姓名：" +
//                            new String(strFaceSnapMatch.struBlackListInfo.struBlackListInfo.struAttribute.byName).trim() + "，黑名单证件信息：" +
//                            new String(strFaceSnapMatch.struBlackListInfo.struBlackListInfo.struAttribute.byCertificateNumber).trim();
                    //报警设备IP地址
                    //sIP = new String(pAlarmer.sDeviceIP).split("\0", 2);
                    break;
                default:
                    //报警设备IP地址
                    //sIP = new String(pAlarmer.sDeviceIP).split("\0", 2);
                    break;
            }
        }
    }

}
